package test3_12;

public class Homework6_3_maxMinAndAverage {
    public static void main(String[] args) {
        /*
        静态初始化二维数组 {{9},{2,7}，{4,1,6},{2,17,5}}，求出最大数，最小数和平均值
         */

        //初始化max，min，sum，average,count用来存储最大值，最小值，总和,平均值和元素个数
        int max = 0;
        int min = 100;
        int sum = 0;
        double average = 0;
        double count = 0;
        //定义一个二维数组array
        int[][] array = {{9}, {2, 7}, {4, 1, 6}, {2, 17, 5}};
        //用双层for循环，比较，得出最大值最小值和总和
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                if (array[i][j] > max) {
                    max = array[i][j];
                } else if (array[i][j] < min) {
                    min = array[i][j];
                }
                //用sum计算每次循环得到的数组总和
                sum += array[i][j];
                count++;
            }
        }
        //用总和除以个数
        average = sum / count;
        System.out.println("最大值为：" + max + " 最小值为：" + min + " 平均值为：" + average);
    }
}
